package action.querywork;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import model.Work;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import service.queryWorkService;
import service.submitWorkService;

import com.opensymphony.xwork2.ActionSupport;

@Namespace("")
@Action(
	value="StuqueryAllWork",
	results={
			@Result(name="success",location="/WEB-INF/checkResult.jsp")
	}		
)
public class StuqueryAllWork extends ActionSupport{

	public String execute() throws Exception{
		ArrayList<Work> WorkList=new ArrayList<Work>();
		queryWorkService qws=new queryWorkService();
		submitWorkService sws=new submitWorkService();
	    HttpServletRequest request=ServletActionContext.getRequest();
        HttpSession session=request.getSession();
        String user_id=(String) session.getAttribute("user_id");
		try {
			 WorkList=qws.queryAllWork();
			 for(Work work:WorkList){
				String submitstate=sws.querysubmitState(work.getWork_id(),user_id);
				work.setSubmitstate(submitstate);
			 }
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		request.setAttribute("WorkList", WorkList);
		return  SUCCESS;
	}

}
